﻿using ImageMagick;
using System;
using System.Threading.Tasks;

namespace XYZShell.CSHelper
{
    /// <summary>
    /// imagemagick 库的帮助类
    /// https://github.com/dlemstra/Magick.NET
    /// https://imagemagick.org
    /// </summary>
    public static class MagickHelper
    {
        public static async Task Pdf2Image(string pdfFileName, int page, int size, string exportFileName)
        {
            var settings = new MagickReadSettings();
            // Settings the density to 300 dpi will create an image with a better quality
            settings.Density = new Density(300);

            using (var images = new MagickImageCollection())
            {
                // Add all the pages of the pdf file to the collection
                images.Read("Snakeware.pdf", settings);

                // Create new image that appends all the pages horizontally
                using (var horizontal = images.AppendHorizontally())
                {
                    // Save result as a png
                    horizontal.Write("Snakeware.horizontal.png");
                }

                // Create new image that appends all the pages vertically
                using (var vertical = images.AppendVertically())
                {
                    // Save result as a png
                    vertical.Write("Snakeware.vertical.png");
                }
            }
        }
    }
}
